﻿using System;
using System.Collections.Generic;

namespace Host
{
	public delegate Object CallInfo(Dictionary<string, object> data);

	public class CallDescriptionComponents: IComponents
	{
		private Dictionary<string, CallInfo> _callinfo_list = new Dictionary<string, CallInfo>();

		public CallDescriptionComponents() { }

		/// <summary>
		/// 添加对应的调用信息
		/// </summary>
		/// <param name="name">Name.</param>
		/// <param name="callinfo">Callinfo.</param>
		public void AddCallInfo(string name, CallInfo callinfo)
		{
			TAssert.Assert(!_callinfo_list.ContainsKey(name), "Have Same Name CallInfo");
			TAssert.IsNotNull(callinfo, "CallInfo Must Not Be null");

			_callinfo_list.Add(name, callinfo);
		}

		/// <summary>
		/// Removes the call info.
		/// </summary>
		/// <param name="name">Name.</param>
		public void RemoveCallInfo(string name)
		{
			if (_callinfo_list.ContainsKey(name))
			{
				_callinfo_list.Remove(name);
			}
		}

		/// <summary>
		/// Gets all call info.
		/// </summary>
		/// <returns>The all call info.</returns>
		public IEnumerable<KeyValuePair<string, CallInfo>> GetAllCallInfo()
		{
			List<KeyValuePair<string, CallInfo>> list = new List<KeyValuePair<string, CallInfo>>();

			foreach (var item in _callinfo_list.Keys)
			{
				list.Add(new KeyValuePair<string, CallInfo>(item, _callinfo_list[item]));
			}

			return list;
		}
	}

}
